package com.ee.chat.admin.controller.systemmanage;

import com.ee.chat.admin.service.IAdminUserService;
import com.ee.chat.common.bean.Result;
import com.ee.chat.common.entity.AdminUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("adminUser")
public class AdminUserController {
    private Logger log = LoggerFactory.getLogger(AdminUserController.class);

    @Resource
    IAdminUserService adminService;

    @RequestMapping("list")
    public Result list(HttpServletRequest request, @RequestParam Integer page, @RequestParam Integer limit){
        try {
            return adminService.list(request, page, limit);
        } catch (Exception e){
            log.error("【获取管理员用户列表错误】", e);
        }
        return Result.returnFailure();
    }

    @RequestMapping("del")
    public Result del(HttpServletRequest request, @RequestParam("ids[]") List<Integer> ids){
        try {
            return adminService.del(request, ids);
        } catch(Exception e){
            log.error("【删除管理员用户错误】", e);
        }
        return Result.returnFailure();
    }

    @RequestMapping("toEdit")
    public Result toEdit(HttpServletRequest request, @RequestParam(required = false) Integer id){
        try {
            return adminService.toEdit(request, id);
        } catch(Exception e){
            log.error("【编辑管理员用户错误】", e);
        }
        return Result.returnFailure();
    }

    @RequestMapping("edit")
    public Result edit(HttpServletRequest request, AdminUser adminUser){
        try {
            return adminService.edit(request, adminUser);
        } catch(Exception e){
            log.error("【保存管理员用户错误】", e);
        }
        return Result.returnFailure();
    }

    @RequestMapping("add")
    public Result add(HttpServletRequest request, AdminUser adminUser){
        try {
            return adminService.save(request, adminUser);
        } catch(Exception e){
            log.error("【保存管理员用户错误】", e);
        }
        return Result.returnFailure();
    }

    @RequestMapping("restPwd")
    public Result restPwd(HttpServletRequest request, @RequestParam Integer id){
        try {
            return adminService.restPwd(request, id);
        } catch(Exception e){
            log.error("【重置管理员用户密码错误】", e);
        }
        return Result.returnFailure();
    }

    @RequestMapping("changeStatus")
    public Result changeStatus(HttpServletRequest request, @RequestParam Integer id){
        try {
            return adminService.changeStatus(request, id);
        } catch(Exception e){
            log.error("【变更管理员用户状态错误】", e);
        }
        return Result.returnFailure();
    }
}
